package com.cloud.servlet;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.core.BaseServlet;
import com.cloud.dao.CodeBean;
import com.cloud.dao.HospitalBean;
import com.cloud.service.CodeService;
import com.cloud.service.FileService;
import com.cloud.util.Code;
import com.cloud.util.CommUtil;

/**
 * 1Cloud1
 * @author Administrator
 * @since 2015-12-5
 * @version 1.0 
 */
@Controller
@RequestMapping("/code")
public class CodeServlet extends BaseServlet {
	@Autowired
	private CodeService CodeService;
	@Autowired
	private FileService FileService;
	
	/**
	 * 科室信息
	 * @return
	 */
	@RequestMapping(value = "/department", method = { RequestMethod.GET})
	public @ResponseBody Object department(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<CodeBean> retList = CodeService.getDepartmentList();
		map.put("code", Code.C200.key);
		map.put("msg", Code.C200.desc);
		map.put("data", retList);
		return map;
	}

	/**
	 * 地域信息
	 * @return
	 */
	@RequestMapping(value = "/dict", method = { RequestMethod.GET})
	public @ResponseBody Object dict(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<CodeBean> retList = CodeService.getDictList();
		map.put("code", Code.C200.key);
		map.put("msg", Code.C200.desc);
		map.put("data", retList);
		return map;
	}
	
	/**
	 * 疾病信息
	 * @return
	 */
	@RequestMapping(value = "/disease", method = { RequestMethod.GET})
	public @ResponseBody Object disease(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<CodeBean> retList = CodeService.getDiseaseList();
		map.put("code", Code.C200.key);
		map.put("msg", Code.C200.desc);
		map.put("data", retList);
		return map;
	}
	
	/**
	 * 职称信息
	 * @return
	 */
	@RequestMapping(value = "/title", method = { RequestMethod.GET})
	public @ResponseBody Object title(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<CodeBean> retList = CodeService.getTitleList();
		map.put("code", Code.C200.key);
		map.put("msg", Code.C200.desc);
		map.put("data", retList);
		return map;
	}
	
	/**
	 * 获取医院信息
	 * @param request
	 * @param hospital
	 * @return
	 */
	@RequestMapping(value = "/hospital", method = { RequestMethod.GET})
	public @ResponseBody Object hospital(HttpServletRequest request, HospitalBean hospital) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<HospitalBean> retList = CodeService.getHospitalList(hospital);
		for(HospitalBean info : retList){
			if(!CommUtil.isEmpty(info.getLogo()))
				info.setLogo(FileService.getVisitUrl(info.getLogo()));
			if(!CommUtil.isEmpty(info.getPics()))
				info.setPics(FileService.getVisitUrl(info.getPics()));
		}
		map.put("code", Code.C200.key);
		map.put("msg", Code.C200.desc);
		map.put("data", retList);
		return map;
	}
	
	/**
	 * 公司信息
	 * @return
	 */
	@RequestMapping(value = "/company", method = { RequestMethod.GET})
	public @ResponseBody Object company(HttpServletRequest request, String name) {
		Map<String, Object> map = new HashMap<String, Object>();
		List<CodeBean> retList = CodeService.getCompanyList(name);
		map.put("code", Code.C200.key);
		map.put("msg", Code.C200.desc);
		map.put("data", retList);
		return map;
	}
}
